import request from '../request'

// 告警严重程度类型
export type AlertSeverity = 'WARNING' | 'URGENT'

// 告警详情接口
export interface AlertDetails {
  金额使用: {
    need_supplement: number
    completion_ratio: string
  }
}

// 项目告警接口
export interface ProjectAlert {
  project_id: number
  project_code: string
  customer_name: string
  alert_date: string
  project_end_date: string
  days_to_80_percent: number
  total_contract_days: number
  severity: AlertSeverity
  alert_details: AlertDetails
  total_alert_count: number
  id: number
  created_time: string
  updated_time: string
}

// 分页响应接口
export interface PaginatedResponse<T> {
  items: T[]
  total?: number
  page?: number
  page_size?: number
  has_next?: boolean
  has_prev?: boolean
}

// API响应接口
export interface AlertsResponse {
  code: number
  message: string
  data: PaginatedResponse<ProjectAlert>
}

// 查询参数接口
export interface AlertsQueryParams {
  severity?: AlertSeverity
  page?: number
  page_size?: number
}

// 告警服务
export const alertsService = {
  // 获取项目告警列表
  async getProjectAlerts(params: AlertsQueryParams = {}): Promise<AlertsResponse> {
    const queryParams = {
      page_size: 10,
      sort_by: "project_end_date",
      sort_order: "asc",
      ...params
    }
    
    return request.get('/alerts/projects', queryParams)
  }
}